<template>
  <van-list class="business-list" v-model:loading="loadLoading" :finished="finished" @load="onLoad">
    <div v-for="item in businessList" :key="item.id" class="box business-item" @click="businessHandle(item.id)">
      <img :src="item.avatar" :alt="item.name" class="business-avatar" />
      <div class="name">{{ item.name }}</div>
    </div>
  </van-list>
</template>
<script setup lang="ts">
import type { BusinessItemResult } from '@/types/business'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const props = defineProps<{
  businessList: BusinessItemResult[]
  total: number
}>()
const emits = defineEmits<{
  (e: 'getBusinessList'): void
}>()
// 加载状态
const loadLoading = ref(false)
const finished = ref(false)
const businessHandle = (id: number) => {
  router.push({ path: '/business', query: { id: id } })
}
const onLoad = () => {
  if (props.businessList.length >= props.total) {
    finished.value = true
  } else {
    emits('getBusinessList')
    loadLoading.value = false
  }
}
</script>
<style scoped lang="scss">
.business-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr); /* 定义两列，每列等宽，占1份剩余空间 */
  grid-gap: 10px; /* 网格元素之间的间距为20px */
  margin: 10px;
}
.business-item {
  min-height: 150px;
  margin: 0;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  .business-avatar {
    width: 100%;
    max-height: 120px;
    font-size: 12px;
    object-fit: cover;
    border-radius: 10px 10px 0 0;
  }
  .name {
    margin: 5px 0;
  }
}
.business-info {
  flex: 1;
  height: 80px;
  margin-left: 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  .name {
    display: flex;
    justify-content: space-between;
    font-weight: 600;
    span {
      color: #999;
      font-size: 14px;
    }
  }
  .phone,
  .open-time {
    color: #999;
    font-size: 12px;
  }
}
</style>
